package top.haijunit.work.configurer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.ServletRequestHandledEvent;

/**
 * 打印请求日志
 *
 * @author zhanghaijun
 * @since 2024-08-09
 */
@Slf4j
@Component
public class TimeCountListener implements ApplicationListener<ServletRequestHandledEvent> {

    @Override
    public void onApplicationEvent(ServletRequestHandledEvent event) {
        Throwable failureCause = event.getFailureCause();
        log.info("请求日志，{}", event.getDescription());
        if (failureCause != null) {
            log.error("请求日志，【失败】发生了错误原因: {}", failureCause.getMessage(), failureCause);
        }
    }
}
